class Loading {
    constructor() {
        this.close = this.close.bind(this)
        this.open = this.open.bind(this)
    }

    html (parameter?: any) {
        let box = null
        let body = null
        let ul = null
        let li = null
        let obj: any = {}

        if (typeof parameter === 'string') {
            obj.message = parameter
        } else {
            obj = parameter
        }
        ul = document.createElement('ul')

        for (let i = 0; i < 9; i++) {
            li = document.createElement('li')
            ul.appendChild(li)
        }

        body = document.createElement('div')
        body.appendChild(ul)
        box = document.createElement('div')
        box.className = 'loading'
        box.setAttribute('id', 'loading')
        box.appendChild(body)

        return box
    }
    
    open () {
        let id = document.getElementById('loading')
        let dom = this.html()
        if (!id) {
            document.body.appendChild(dom)
        }
    }

    close () {
        let id = document.getElementById('loading')
        if (id) {
            id.remove()
        }
    }
}

export default new Loading()
